<template>
	<view class="pay-order">
		<view class="order-info-holder">
			<view class="row">
				<text>订单编号：</text>{{orderInfo.orderSn}}
			</view>
			<view class="row">
				<text>订单金额：</text>{{orderInfo.totalAmount}}元
			</view>
		</view>

		<view class="pay-choice">
			<view class="title">
				选择支付方式
			</view>
			<radio-group @change="getPayType">
				<view class="row">
					<view class="left">
						<image src="/static/icons/alipay.png" mode=""></image>
						<text>支付宝支付</text>
					</view>
					<view class="right">
						<radio value="1" color="#354e44" :checked="payType == 1" />
					</view>
				</view>
				<view class="row">
					<view class="left">
						<image src="/static/icons/wxpay.png" mode=""></image>
						<text>微信支付</text>
					</view>
					<view class="right">
						<radio value="2" color="#354e44" :checked="payType == 2" />
					</view>
				</view>
			</radio-group>
		</view>

		<view class="btn-holder">
			<view class="pay-btn" @tap="payOrder">
				立即支付
			</view>
			<view class="pay-desc">
				点击立即支付，即代表您同意<text>《条款协议》</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		requestPayOrder
	} from 'api/user/order.js';
	export default {
		data() {
			return {
				orderId: '',
				orderInfo: uni.getStorageSync('orderInfo'),
				payType: '1',
			};
		},
		methods: {
			getPayType(e) {
				this.payType = e.detail.value;
			},
			payOrder() {
				requestPayOrder({
					payType: Number(this.payType),
					orderId: this.orderId
				}).then(res => {
					console.log(res);
					if(res.code === 20000){
						uni.showToast({
							title:'支付成功',
							icon:'success',
							duration:1000
						})
						uni.navigateTo({
							url:'/pages/user/cart/pay-success/pay-success',
						})
					}
				})
			}
		},
		onLoad(e) {
			this.orderId = e.orderId;
		},
	}
</script>

<style lang="scss" scoped>
	.pay-order {
		box-sizing: border-box;
		padding: 22rpx;
		width: 100%;

		.order-info-holder {
			.row {
				width: 100%;
				height: 90rpx;
				font-size: 32rpx;

				text {
					font-size: 32rpx;
					color: #7d7d7d;
				}
			}
		}

		.pay-choice {
			margin-top: 20rpx;

			.title {
				width: 100%;
				font-size: 34rpx;
			}

			.row {
				margin-top: 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					display: flex;
					align-items: center;

					image {
						display: block;
						width: 80rpx;
						height: 80rpx;
					}
				}

			}
		}

		.btn-holder {
			margin-top: 50rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: center;

			.pay-btn {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 70%;
				height: 80rpx;
				font-size: 32rpx;
				color: #fff;
				background-color: #354e44;
				border-radius: 80rpx;
				box-shadow: 0px 4rpx 10rpx rgba(0, 0, 0, .2);
			}

			.pay-desc {
				font-size: 24rpx;
				margin-top: 10rpx;
				color: #999;

				text {
					color: #5a9ef7;
				}
			}
		}
	}
</style>
